package com.itheima.goods.controller;

import com.itheima.goods.pojo.Spec;
import com.itheima.goods.service.SpecService;
import entity.PageResult;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    @GetMapping("/fandAll")
    public Result fandAll() {

        return this.specService.fandAll();
    }

    @PostMapping("/add")
    public Result add(
            Spec spec
    ) {
        return this.specService.add(spec);
    }

    @GetMapping("/findPage")
    public PageResult<Spec> findPage(
            @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @RequestParam(value = "queryString", required = false) String queryString
    ) {
        return this.specService.findPage(currentPage, pageSize, queryString);
    }

    @GetMapping("/{id}}")
    public Result findById(
            @RequestParam("id") Integer id) {
        return this.specService.findById(id);
    }

    @PutMapping
    public Result upDateSpec(@RequestParam("id") Integer id, @RequestBody Spec spec) {
        return this.specService.upDateSpec(id, spec);
    }

    @DeleteMapping
    public Result deleteSpec(@RequestParam("id") Integer id) {
        return this.specService.deleteSpec(id);
    }
}
